<%@page import="Model.CommitteeRole"%>
<%@page import="Logic.CommitteeModify_BLL"%>
<%@page import="Logic.Authorizer"%>
<%@page import="Model.Committee"%>
<%@page import="Model.Staff"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%
	if (session.getAttribute("name") == null) {
		response.sendRedirect("login.jsp");
	} else {
		if (Authorizer.checkRole("1", session.getAttribute("role")
				.toString()) || Authorizer.checkRole("3", session.getAttribute("role").toString()) || (session
						.getAttribute("role").equals("2"))) {
 
		}
		else
		{
			response.sendRedirect("nopermission.jsp");
						
		}
	}
%>


<!-- Declare the first header -->
<jsp:include page="t_header.jsp" />


<jsp:include page="header.html" />
<!-- Declare sidebar -->
<jsp:include page="t_siderbarcommittee.jsp" />

<!-- Main Content -->
<section id="main" class="column">
	<%
		Committee comm = new Committee();
		if (request.getParameter("id") != null) {
			try {
				comm = CommitteeModify_BLL.getCommitteeById(request
						.getParameter("id"));
			}catch(NullPointerException nullPtrEx)
			{
				System.out.println(nullPtrEx.getLocalizedMessage());
				System.out.println("Somehow something went wrong ;x");
			}
			catch (Exception e) {
				System.out.println(e);
			}
		}
	%>
	<%
	try{
		if (request.getParameter("action") != null) {
			if (request.getParameter("action").equals("d"))
				out.print("<h4 class='alert_warning'>Please confirm your deletion of &quot;"
						+ comm.getTitle() + "&quot;.</h4>");
			else if (request.getParameter("action").equals("e"))
				out.print("<h4 class='alert_info'>You are now editing &quot;"
						+ comm.getTitle() + "&quot;.</h4>");
		}
	}catch(NullPointerException nullPtrEx)
	{
		System.out.println("Action not detected!");
	}
	%>

	<%
		if (request.getParameter("error") != null) {
			if (request.getParameter("error").equals("1"))
				out.print("<h4 class='alert_error'>Error - Please fill in all fields.</h4>");
			else if (request.getParameter("error").equals("2"))
				out.print("<h4 class='alert_error'>Error - Title taken. Please choose a different title.</h4>");
			else if (request.getParameter("error").equals("-1"))
				out.print("<h4 class='alert_success'>Staffs appointed to committee successfully.</h4>");
		}
	%>

	<%
		if (request.getParameter("action") != null
				&& request.getParameter("action").equals("d")
				&& request.getParameter("id") != null) {
	%>
	<article class="module width_3_quarter">
		<form action="DeleteCommittee" method="POST">
			<header>
				<h3>Confirm Delete?</h3>
			</header>
			<div class="module_content">
				<h2>Are you sure you want to delete this committee? You cannot
					undo this action!</h2>
				<input name="id" type="hidden"
					value="<%=request.getParameter("id")%>" /> <input name="search"
					type="hidden" value="<%=request.getParameter("search")%>" />
				<div class="clear"></div>
			</div>
			<footer>
				<div class="submit_link">
					<input type="submit" name="submit" value="Confirm Delete"
						class="alt_btn"> <input type="submit" name="submit"
						value="Cancel" class="alt_btn">

				</div>
			</footer>
		</form>
	</article>
	<%
		}
	%>
	<!-- end of post new article -->
	<div class="clear"></div>

	<%
		if (request.getParameter("action") != null
				&& request.getParameter("action").equals("e")
				&& request.getParameter("id") != null) {
			try{
	%>
	<article class="module width_3_quarter">
		<form action="EditCommittee" method="POST">
		
			<header>
				<h3>edit COMMITTEE</h3>
			</header>
			<div class="module_content">
				<fieldset>
					<label>Title</label> <input type="text" maxlength="70" name="title"
						value="<%=comm.getTitle()%>">
				</fieldset>
				<fieldset>
					<label>Purpose</label> <input type="text" maxlength="300"
						name="purpose" value="<%=comm.getPurpose()%>">
				</fieldset>
				<fieldset>
					<label>Roles & Responsibilities</label>
					<textarea rows="5" name="r&r"><%=comm.getRolesResponsibility()%></textarea>
				</fieldset>
				<fieldset>
					<label>Effective Date</label> <input name="effectivedate"
						type="text" id="inputField" readonly="readonly"
						value="<%=comm.getDate()%>" />
				</fieldset>
				<fieldset>
					<label>Frequency of meeting - Optional</label> <input type="text"
						maxlength="70" name="fom"
						value="<%=comm.getFrequencyOfMeeting()%>">
				</fieldset>
			</div>
			<footer>
				<input type="hidden" name="id" value="<%=comm.getId()%>"> <input
					type="hidden" name="originalTitle" value="<%=comm.getTitle()%>">
				<input type="hidden" name="originalPurpose"
					value="<%=comm.getPurpose()%>"> <input type="hidden"
					name="originalR&R" value="<%=comm.getRolesResponsibility()%>">
				<input type="hidden" name="originalDate" value="<%=comm.getDate()%>">
				<input type="hidden" name="originalFom"
					value="<%=comm.getFrequencyOfMeeting()%>"> <input
					name="search" type="hidden"
					value="<%=request.getParameter("search")%>" />
				<div class="submit_link">
					<input name="submit" type="submit" value="Cancel" class="alt_btn">
					<input name="submit" type="submit" value="Save & Continue" class="alt_btn">
				</div>
			</footer>
		</form>
	</article>
	<%
			}catch(NullPointerException nullptrEx)
			{
				System.out.println("Cannot retrieve values");
			}
		}
	%>
	<!-- end of post new article -->
	<div class="spacer"></div>
</section>

<!-- Declare closing tags -->
<jsp:include page="t_footer.jsp" />